﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        GetTopNews();
        GetNhaHang();
        Get5Res();
    }
    protected void GetTopNews()
    {
        SQLHelper Dal = new SQLHelper();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_GetTop5NewestNews";
        DataTable db = Dal.GetDataTable();
        rptTopHotNews.DataSource = db;
        rptTopHotNews.DataBind();
    }
    protected void GetNhaHang()
    {
        StringUtil str = new StringUtil();
        string tennhahang = str.RemoveSign4VietnameseString(Request.QueryString["TenNhaHang"].ToString());
        string diachi = str.RemoveSign4VietnameseString(Request.QueryString["DiaChi"].ToString());
        //try
        //{
            SQLHelper Dal = new SQLHelper();
            Dal.CommandType = CommandType.StoredProcedure;
            Dal.CommandText = "SP_Search";
            Dal.ParameterCollection = new string[2] { "@TenNhaHang","@DiaChi"};
            Dal.ValueCollection = new string[2] { tennhahang, diachi };
            DataTable db = Dal.GetDataTable();
            if (db.Rows.Count==0)
                lblInfo.Text = "Không tìm thấy kết quả nào với từ khóa " + Request.QueryString["TenNhaHang"].ToString();
            else
            {
                rptRes.DataSource = db;
                rptRes.DataBind();
            }
        //}
        //catch
        //{
        //    Response.Redirect("~/Error.aspx");
        //}
    }
    protected void Get5Res()
    {
        SQLHelper Dal = new SQLHelper();
        Dal.Open();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_GetTop5ResHot";
        DataTable db = Dal.GetDataTable();
        Repeater2.DataSource = db;
        Repeater2.DataBind();
    }
}
